<template>
  <el-dialog
    title="确认付款"
    v-model="visible"
    width="30%"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-form
      :model="form"
      :inline="true"
      :rules="rules"
      ref="dialogForm"
      label-width="auto"
      label-position="right"
      class="noFlex"
    >
      <el-form-item label="支付方式" prop="payType">
        <el-select
          v-model="form.payType"
          placeholder="请选择支付方式"
          style="width: 100%"
          clearable
        >
          <el-option
            v-for="item in payTypeOptions"
            :key="item.value"
            :label="item.name"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="付款账号" prop="payAccount">
        <el-input
          v-model="form.payAccount"
          clearable
          placeholder="请输入付款账号"
        ></el-input>
      </el-form-item>
      <el-form-item label="支付时间" prop="confirmPayTime">
        <el-date-picker
          v-model="form.confirmPayTime"
          type="datetime"
          value-format="YYYY-MM-DD HH:mm:ss"
          placeholder="选择日期时间"
          style="width: 100%"
        >
        </el-date-picker>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()"
        >保 存</el-button
      >
    </template>
  </el-dialog>
</template>
<script>
import { queryTypeByDic } from '@/utils/getData'
export default {
  emits: ['success', 'closed'],
  data () {
    return {
      visible: false,
      isSaveing: false,
      money: '',
      //表单数据
      form: {
        id: '',
        payAccount: "",  //付款账号
        confirmPayTime: this.$TOOL.dateFormat(new Date()),//付款时间
        payType: ''//支付方式
      },
      payTypeOptions: [],//支付方式
      //验证规则
      rules: {
        payAccount: [
          { required: true, message: '请输入付款账号', }
        ],
        payType: [
          { required: true, message: '请选择支付方式', trigger: 'change' }
        ],
        confirmPayTime: [
          { type: 'date', required: true, message: '请选择付款时间', trigger: 'change' }
        ],
      }
    }
  },
  mounted () {
    this.getType()
  },
  methods: {
    // 获取回款支付方式
    async getType () {
      this.payTypeOptions = await queryTypeByDic('payment')
    },
    //显示
    open (data) {
      console.log(data)
      this.visible = true
      this.form.id = data.id
    },
    //表单提交方法
    submit () {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true
          let res = await this.$API.payment.confirmPayment.post(this.form)
          if (res.code == 200) {
            this.$emit('success')
            this.visible = false
            this.isSaveing = false
            this.$message.success("操作成功")
          }
        }
      })
    },

  }
}
</script>
  
<style lang="scss" scoped>
.formRow {
  :deep(.el-form-item__content) {
    flex-wrap: nowrap;
    .el-button {
      margin-left: 10px;
    }
  }
}
</style>
  